package com.celesea.configuration.redis;

import com.alibaba.fastjson.JSON;
import com.celesea.configuration.security.SecurityConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.StringRedisTemplate;

@Configuration
public class RedisConfiguration {
    private static Logger logger = LoggerFactory.getLogger(SecurityConfiguration.class);

    @Autowired
    private RedisProperties redisProperties;

    @Bean("connectionFactory")
    public JedisConnectionFactory connectionFactory() {
        logger.info("cas redis info:{}", JSON.toJSONString(redisProperties));
        return redisProperties.connectionFactory();
    }

    @Bean("redisTemplate")
    public StringRedisTemplate redisTemplate(@Qualifier("connectionFactory") RedisConnectionFactory connectionFactory) {
//    public StringRedisTemplate redisTemplate() {
//        RedisConnectionFactory redisConnectionFactory=redisConnectionFactory();
        StringRedisTemplate template = new StringRedisTemplate();
        template.setConnectionFactory(connectionFactory);
        return template;
    }
}
